using UnityEngine;
using UnityEngine.Tilemaps;

namespace Game.Terrain
{
    public class MapEntityBase : TileBase
    {
        [Header("实体属性")]
        public string entityId; // 实体唯一标识
        public EntityType entityType; // 实体类型

        [Header("渲染属性")]
        public Sprite tileSprite; // 实体的 Sprite
        public Color tileColor = Color.white; // 实体的颜色
        public Tile.ColliderType colliderType = Tile.ColliderType.Grid; // 实体的碰撞类型
        public Vector3 position; // 实体的位置
        public Quaternion rotation;
        public Vector3 scale;
        private Matrix4x4 transformMatrix;
        /// <summary>
        /// 实体类型枚举
        /// </summary>
        public enum EntityType
        {
            None,
            Player,
            Enemy,
            Obstacle,
            Item,
            NPC
        }

        /// <summary>
        /// 获取 Tile 数据
        /// </summary>
        public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
        {
            tileData.sprite = tileSprite;
            tileData.color = tileColor;
            tileData.colliderType = colliderType;
            tileData.transform = Matrix4x4.identity;
            tileData.flags = TileFlags.LockTransform;
        }

        /// <summary>
        /// 初始化 Tile
        /// </summary>
        public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go)
        {
            // 在这里可以执行一些初始化操作
            if (go != null)
            {
                // 例如，为 Tile 添加自定义组件
                // var entity = go.GetComponent<EntityBehaviour>();
                // if (entity == null)
                // {
                //     entity = go.AddComponent<EntityBehaviour>();
                // }
               // entity.Initialize(this);
            }
            return true;
        }
    }
}
